@shopify/react-native-skia 1.3.2 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/android/cpp/jni/JniPlatformContext.cpp +4 -3
  2. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +59 -1
  3. package/android/cpp/rnskia-android/RNSkAndroidVideo.h +4 -0
  4. package/android/src/main/java/com/shopify/reactnative/skia/RNSkVideo.java +80 -7
  5. package/cpp/api/JsiVideo.h +32 -7
  6. package/cpp/rnskia/RNSkVideo.h +4 -0
  7. package/ios/RNSkia-iOS/RNSkiOSVideo.h +13 -4
  8. package/ios/RNSkia-iOS/RNSkiOSVideo.mm +65 -67
  9. package/lib/commonjs/dom/nodes/datatypes/Fitting.js +42 -30
  10. package/lib/commonjs/dom/nodes/datatypes/Fitting.js.map +1 -1
  11. package/lib/commonjs/external/reanimated/useVideo.d.ts +16 -4
  12. package/lib/commonjs/external/reanimated/useVideo.js +92 -17
  13. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
  14. package/lib/commonjs/external/reanimated/useVideoLoading.d.ts +4 -0
  15. package/lib/commonjs/external/reanimated/useVideoLoading.js +27 -0
  16. package/lib/commonjs/external/reanimated/useVideoLoading.js.map +1 -0
  17. package/lib/commonjs/external/reanimated/useVideoLoading.web.d.ts +4 -0
  18. package/lib/commonjs/external/reanimated/useVideoLoading.web.js +20 -0
  19. package/lib/commonjs/external/reanimated/useVideoLoading.web.js.map +1 -0
  20. package/lib/commonjs/renderer/components/shapes/FitBox.d.ts +2 -10
  21. package/lib/commonjs/renderer/components/shapes/FitBox.js +32 -3
  22. package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
  23. package/lib/commonjs/skia/core/Matrix.js +5 -1
  24. package/lib/commonjs/skia/core/Matrix.js.map +1 -1
  25. package/lib/commonjs/skia/types/Matrix.js +2 -0
  26. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  27. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -1
  28. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +4 -2
  29. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  30. package/lib/commonjs/skia/types/Skia.d.ts +1 -1
  31. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  32. package/lib/commonjs/skia/types/Video/Video.d.ts +9 -1
  33. package/lib/commonjs/skia/types/Video/Video.js.map +1 -1
  34. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.d.ts +9 -0
  35. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js +30 -0
  36. package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js.map +1 -0
  37. package/lib/commonjs/skia/web/JsiSkImageFactory.js +8 -2
  38. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkia.js +2 -3
  40. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  41. package/lib/commonjs/skia/web/JsiVideo.d.ts +24 -0
  42. package/lib/commonjs/skia/web/JsiVideo.js +83 -0
  43. package/lib/commonjs/skia/web/JsiVideo.js.map +1 -0
  44. package/lib/commonjs/views/SkiaDomView.js +2 -0
  45. package/lib/commonjs/views/SkiaDomView.js.map +1 -1
  46. package/lib/commonjs/views/SkiaDomView.web.js +2 -0
  47. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  48. package/lib/commonjs/views/SkiaJSDomView.js +2 -0
  49. package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
  50. package/lib/module/dom/nodes/datatypes/Fitting.js +41 -29
  51. package/lib/module/dom/nodes/datatypes/Fitting.js.map +1 -1
  52. package/lib/module/external/reanimated/useVideo.d.ts +16 -4
  53. package/lib/module/external/reanimated/useVideo.js +92 -17
  54. package/lib/module/external/reanimated/useVideo.js.map +1 -1
  55. package/lib/module/external/reanimated/useVideoLoading.d.ts +4 -0
  56. package/lib/module/external/reanimated/useVideoLoading.js +20 -0
  57. package/lib/module/external/reanimated/useVideoLoading.js.map +1 -0
  58. package/lib/module/external/reanimated/useVideoLoading.web.d.ts +4 -0
  59. package/lib/module/external/reanimated/useVideoLoading.web.js +13 -0
  60. package/lib/module/external/reanimated/useVideoLoading.web.js.map +1 -0
  61. package/lib/module/renderer/components/shapes/FitBox.d.ts +2 -10
  62. package/lib/module/renderer/components/shapes/FitBox.js +32 -3
  63. package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
  64. package/lib/module/skia/core/Matrix.js +5 -1
  65. package/lib/module/skia/core/Matrix.js.map +1 -1
  66. package/lib/module/skia/types/Matrix.js +2 -0
  67. package/lib/module/skia/types/Matrix.js.map +1 -1
  68. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -1
  69. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +2 -1
  70. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  71. package/lib/module/skia/types/Skia.d.ts +1 -1
  72. package/lib/module/skia/types/Skia.js.map +1 -1
  73. package/lib/module/skia/types/Video/Video.d.ts +9 -1
  74. package/lib/module/skia/types/Video/Video.js.map +1 -1
  75. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.d.ts +9 -0
  76. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js +23 -0
  77. package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js.map +1 -0
  78. package/lib/module/skia/web/JsiSkImageFactory.js +9 -3
  79. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  80. package/lib/module/skia/web/JsiSkia.js +2 -3
  81. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  82. package/lib/module/skia/web/JsiVideo.d.ts +24 -0
  83. package/lib/module/skia/web/JsiVideo.js +75 -0
  84. package/lib/module/skia/web/JsiVideo.js.map +1 -0
  85. package/lib/module/views/SkiaDomView.js +2 -0
  86. package/lib/module/views/SkiaDomView.js.map +1 -1
  87. package/lib/module/views/SkiaDomView.web.js +2 -0
  88. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  89. package/lib/module/views/SkiaJSDomView.js +2 -0
  90. package/lib/module/views/SkiaJSDomView.js.map +1 -1
  91. package/lib/typescript/src/external/reanimated/useVideo.d.ts +16 -4
  92. package/lib/typescript/src/external/reanimated/useVideoLoading.d.ts +4 -0
  93. package/lib/typescript/src/external/reanimated/useVideoLoading.web.d.ts +4 -0
  94. package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +2 -10
  95. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -1
  96. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  97. package/lib/typescript/src/skia/types/Video/Video.d.ts +9 -1
  98. package/lib/typescript/src/skia/web/CanvasKitWebGLBufferImpl.d.ts +9 -0
  99. package/lib/typescript/src/skia/web/JsiVideo.d.ts +24 -0
  100. package/package.json +1 -1
  101. package/src/dom/nodes/datatypes/Fitting.ts +28 -21
  102. package/src/external/reanimated/useVideo.ts +108 -31
  103. package/src/external/reanimated/useVideoLoading.ts +28 -0
  104. package/src/external/reanimated/useVideoLoading.web.ts +17 -0
  105. package/src/renderer/components/shapes/FitBox.tsx +38 -4
  106. package/src/skia/core/Matrix.ts +4 -2
  107. package/src/skia/types/Matrix.ts +1 -0
  108. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +10 -2
  109. package/src/skia/types/Skia.ts +1 -1
  110. package/src/skia/types/Video/Video.ts +7 -1
  111. package/src/skia/web/CanvasKitWebGLBufferImpl.ts +22 -0
  112. package/src/skia/web/JsiSkImageFactory.ts +16 -3
  113. package/src/skia/web/JsiSkia.ts +2 -3
  114. package/src/skia/web/JsiVideo.ts +96 -0
  115. package/src/views/SkiaDomView.tsx +4 -0
  116. package/src/views/SkiaDomView.web.tsx +4 -0
  117. package/src/views/SkiaJSDomView.tsx +4 -0
  118. package/lib/commonjs/external/reanimated/video.d.ts +0 -16
  119. package/lib/commonjs/external/reanimated/video.js +0 -54
  120. package/lib/commonjs/external/reanimated/video.js.map +0 -1
  121. package/lib/module/external/reanimated/video.d.ts +0 -16
  122. package/lib/module/external/reanimated/video.js +0 -46
  123. package/lib/module/external/reanimated/video.js.map +0 -1
  124. package/lib/typescript/src/external/reanimated/video.d.ts +0 -16
  125. package/src/external/reanimated/video.ts +0 -82
@@ -1,13 +1,38 @@
1
1
  import { useEffect, useMemo } from "react";
2
- import { Skia } from "../../skia/Skia";
2
+ import { Platform } from "../../Platform";
3
3
  import Rea from "./ReanimatedProxy";
4
- import { processVideoState } from "./video";
4
+ import { useVideoLoading } from "./useVideoLoading";
5
+ const copyFrameOnAndroid = currentFrame => {
6
+ "worklet";
7
+
8
+ // on android we need to copy the texture before it's invalidated
9
+ if (Platform.OS === "android") {
10
+ const tex = currentFrame.value;
11
+ if (tex) {
12
+ currentFrame.value = tex.makeNonTextureImage();
13
+ tex.dispose();
14
+ }
15
+ }
16
+ };
17
+ const setFrame = (video, currentFrame) => {
18
+ "worklet";
19
+
20
+ const img = video.nextImage();
21
+ if (img) {
22
+ if (currentFrame.value) {
23
+ currentFrame.value.dispose();
24
+ }
25
+ currentFrame.value = img;
26
+ } else {
27
+ copyFrameOnAndroid(currentFrame);
28
+ }
29
+ };
5
30
  const defaultOptions = {
6
- playbackSpeed: 1,
7
31
  looping: true,
8
32
  paused: false,
9
33
  seek: null,
10
- currentTime: 0
34
+ currentTime: 0,
35
+ volume: 0
11
36
  };
12
37
  const useOption = value => {
13
38
  "worklet";
@@ -22,12 +47,12 @@ const disposeVideo = video => {
22
47
  video === null || video === void 0 || video.dispose();
23
48
  };
24
49
  export const useVideo = (source, userOptions) => {
25
- var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$playback;
26
- const video = useMemo(() => source ? Skia.Video(source) : null, [source]);
50
+ var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$volume;
51
+ const video = useVideoLoading(source);
27
52
  const isPaused = useOption((_userOptions$paused = userOptions === null || userOptions === void 0 ? void 0 : userOptions.paused) !== null && _userOptions$paused !== void 0 ? _userOptions$paused : defaultOptions.paused);
28
53
  const looping = useOption((_userOptions$looping = userOptions === null || userOptions === void 0 ? void 0 : userOptions.looping) !== null && _userOptions$looping !== void 0 ? _userOptions$looping : defaultOptions.looping);
29
54
  const seek = useOption((_userOptions$seek = userOptions === null || userOptions === void 0 ? void 0 : userOptions.seek) !== null && _userOptions$seek !== void 0 ? _userOptions$seek : defaultOptions.seek);
30
- const playbackSpeed = useOption((_userOptions$playback = userOptions === null || userOptions === void 0 ? void 0 : userOptions.playbackSpeed) !== null && _userOptions$playback !== void 0 ? _userOptions$playback : defaultOptions.playbackSpeed);
55
+ const volume = useOption((_userOptions$volume = userOptions === null || userOptions === void 0 ? void 0 : userOptions.volume) !== null && _userOptions$volume !== void 0 ? _userOptions$volume : defaultOptions.volume);
31
56
  const currentFrame = Rea.useSharedValue(null);
32
57
  const currentTime = Rea.useSharedValue(0);
33
58
  const lastTimestamp = Rea.useSharedValue(-1);
@@ -37,18 +62,67 @@ export const useVideo = (source, userOptions) => {
37
62
  }, [video]);
38
63
  const framerate = useMemo(() => {
39
64
  var _video$framerate;
40
- return (_video$framerate = video === null || video === void 0 ? void 0 : video.framerate()) !== null && _video$framerate !== void 0 ? _video$framerate : 0;
65
+ return Platform.OS === "web" ? -1 : (_video$framerate = video === null || video === void 0 ? void 0 : video.framerate()) !== null && _video$framerate !== void 0 ? _video$framerate : 0;
41
66
  }, [video]);
42
- const rotationInDegrees = useMemo(() => {
43
- var _video$getRotationInD;
44
- return (_video$getRotationInD = video === null || video === void 0 ? void 0 : video.getRotationInDegrees()) !== null && _video$getRotationInD !== void 0 ? _video$getRotationInD : 0;
67
+ const size = useMemo(() => {
68
+ var _video$size;
69
+ return (_video$size = video === null || video === void 0 ? void 0 : video.size()) !== null && _video$size !== void 0 ? _video$size : {
70
+ width: 0,
71
+ height: 0
72
+ };
73
+ }, [video]);
74
+ const rotation = useMemo(() => {
75
+ var _video$rotation;
76
+ return (_video$rotation = video === null || video === void 0 ? void 0 : video.rotation()) !== null && _video$rotation !== void 0 ? _video$rotation : 0;
45
77
  }, [video]);
78
+ const frameDuration = 1000 / framerate;
79
+ const currentFrameDuration = Math.floor(frameDuration);
80
+ Rea.useAnimatedReaction(() => isPaused.value, paused => {
81
+ if (paused) {
82
+ video === null || video === void 0 || video.pause();
83
+ } else {
84
+ lastTimestamp.value = -1;
85
+ video === null || video === void 0 || video.play();
86
+ }
87
+ });
88
+ Rea.useAnimatedReaction(() => seek.value, value => {
89
+ if (value !== null) {
90
+ copyFrameOnAndroid(currentFrame);
91
+ video === null || video === void 0 || video.seek(value);
92
+ currentTime.value = value;
93
+ seek.value = null;
94
+ }
95
+ });
96
+ Rea.useAnimatedReaction(() => volume.value, value => {
97
+ video === null || video === void 0 || video.setVolume(value);
98
+ });
46
99
  Rea.useFrameCallback(frameInfo => {
47
- processVideoState(video, duration, framerate, frameInfo.timestamp, {
48
- paused: isPaused.value,
49
- looping: looping.value,
50
- playbackSpeed: playbackSpeed.value
51
- }, currentTime, currentFrame, lastTimestamp, seek);
100
+ "worklet";
101
+
102
+ if (!video) {
103
+ return;
104
+ }
105
+ if (isPaused.value) {
106
+ return;
107
+ }
108
+ const currentTimestamp = frameInfo.timestamp;
109
+ if (lastTimestamp.value === -1) {
110
+ lastTimestamp.value = currentTimestamp;
111
+ }
112
+ const delta = currentTimestamp - lastTimestamp.value;
113
+ const isOver = currentTime.value + delta > duration;
114
+ if (isOver && looping.value) {
115
+ seek.value = 0;
116
+ currentTime.value = seek.value;
117
+ lastTimestamp.value = currentTimestamp;
118
+ }
119
+ // On Web the framerate is uknown.
120
+ // This could be optimized by using requestVideoFrameCallback (Chrome only)
121
+ if (delta >= currentFrameDuration && !isOver || Platform.OS === "web") {
122
+ setFrame(video, currentFrame);
123
+ currentTime.value += delta;
124
+ lastTimestamp.value = currentTimestamp;
125
+ }
52
126
  });
53
127
  useEffect(() => {
54
128
  return () => {
@@ -61,7 +135,8 @@ export const useVideo = (source, userOptions) => {
61
135
  currentTime,
62
136
  duration,
63
137
  framerate,
64
- rotationInDegrees
138
+ rotation,
139
+ size
65
140
  };
66
141
  };
67
142
  //# sourceMappingURL=useVideo.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useMemo","Skia","Rea","processVideoState","defaultOptions","playbackSpeed","looping","paused","seek","currentTime","useOption","value","defaultValue","useSharedValue","isSharedValue","disposeVideo","video","dispose","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$seek","_userOptions$playback","Video","isPaused","currentFrame","lastTimestamp","duration","_video$duration","framerate","_video$framerate","rotationInDegrees","_video$getRotationInD","getRotationInDegrees","useFrameCallback","frameInfo","timestamp","runOnUI"],"sources":["useVideo.ts"],"sourcesContent":["import { type FrameInfo } from \"react-native-reanimated\";\nimport { useEffect, useMemo } from \"react\";\n\nimport { Skia } from \"../../skia/Skia\";\nimport type { SkImage, Video } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\nimport {\n processVideoState,\n type Animated,\n type PlaybackOptions,\n} from \"./video\";\n\nconst defaultOptions = {\n playbackSpeed: 1,\n looping: true,\n paused: false,\n seek: null,\n currentTime: 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 playbackSpeed = useOption(\n userOptions?.playbackSpeed ?? defaultOptions.playbackSpeed\n );\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 rotationInDegrees = useMemo(\n () => video?.getRotationInDegrees() ?? 0,\n [video]\n );\n Rea.useFrameCallback((frameInfo: FrameInfo) => {\n processVideoState(\n video,\n duration,\n framerate,\n frameInfo.timestamp,\n {\n paused: isPaused.value,\n looping: looping.value,\n playbackSpeed: playbackSpeed.value,\n },\n currentTime,\n currentFrame,\n lastTimestamp,\n seek\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 { currentFrame, currentTime, duration, framerate, rotationInDegrees };\n};\n"],"mappings":"AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAE1C,SAASC,IAAI,QAAQ,iBAAiB;AAGtC,OAAOC,GAAG,MAAM,mBAAmB;AACnC,SACEC,iBAAiB,QAGZ,SAAS;AAEhB,MAAMC,cAAc,GAAG;EACrBC,aAAa,EAAE,CAAC;EAChBC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE,IAAI;EACVC,WAAW,EAAE;AACf,CAAC;AAED,MAAMC,SAAS,GAAOC,KAAkB,IAAK;EAC3C,SAAS;;EACT;EACA,MAAMC,YAAY,GAAGV,GAAG,CAACW,cAAc,CACrCX,GAAG,CAACY,aAAa,CAACH,KAAK,CAAC,GAAGA,KAAK,CAACA,KAAK,GAAGA,KAC3C,CAAC;EACD,OAAOT,GAAG,CAACY,aAAa,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAGC,YAAY;AACxD,CAAC;AAED,MAAMG,YAAY,GAAIC,KAAmB,IAAK;EAC5C,SAAS;;EACTA,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEC,O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form","Rea","useVideoLoading","copyFrameOnAndroid","currentFrame","OS","tex","value","makeNonTextureImage","dispose","setFrame","video","img","nextImage","defaultOptions","looping","paused","seek","currentTime","volume","useOption","defaultValue","useSharedValue","isSharedValue","disposeVideo","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$seek","_userOptions$volume","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","runOnUI"],"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,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAG1C,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,OAAOC,GAAG,MAAM,mBAAmB;AACnC,SAASC,eAAe,QAAQ,mBAAmB;AAWnD,MAAMC,kBAAkB,GAAIC,YAAyC,IAAK;EACxE,SAAS;;EACT;EACA,IAAIJ,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;IAC7B,MAAMC,GAAG,GAAGF,YAAY,CAACG,KAAK;IAC9B,IAAID,GAAG,EAAE;MACPF,YAAY,CAACG,KAAK,GAAGD,GAAG,CAACE,mBAAmB,CAAC,CAAC;MAC9CF,GAAG,CAACG,OAAO,CAAC,CAAC;IACf;EACF;AACF,CAAC;AAED,MAAMC,QAAQ,GAAGA,CAACC,KAAY,EAAEP,YAAyC,KAAK;EAC5E,SAAS;;EACT,MAAMQ,GAAG,GAAGD,KAAK,CAACE,SAAS,CAAC,CAAC;EAC7B,IAAID,GAAG,EAAE;IACP,IAAIR,YAAY,CAACG,KAAK,EAAE;MACtBH,YAAY,CAACG,KAAK,CAACE,OAAO,CAAC,CAAC;IAC9B;IACAL,YAAY,CAACG,KAAK,GAAGK,GAAG;EAC1B,CAAC,MAAM;IACLT,kBAAkB,CAACC,YAAY,CAAC;EAClC;AACF,CAAC;AAED,MAAMU,cAAc,GAAG;EACrBC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE,KAAK;EACbC,IAAI,EAAE,IAAI;EACVC,WAAW,EAAE,CAAC;EAC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GAAG+C,gBAAgB;IACxC;IACA,MAAME,KAAK,GAAGF,gBAAgB,GAAGrB,aAAa,CAAC1B,KAAK;IAEpD,MAAMkD,MAAM,GAAGvC,WAAW,CAACX,KAAK,GAAGiD,KAAK,GAAGtB,QAAQ;IACnD,IAAIuB,MAAM,IAAI1C,OAAO,CAACR,KAAK,EAAE;MAC3BU,IAAI,CAACV,KAAK,GAAG,CAAC;MACdW,WAAW,CAACX,KAAK,GAAGU,IAAI,CAACV,KAAK;MAC9B0B,aAAa,CAAC1B,KAAK,GAAG+C,gBAAgB;IACxC;IACA;IACA;IACA,IAAKE,KAAK,IAAIX,oBAAoB,IAAI,CAACY,MAAM,IAAKzD,QAAQ,CAACK,EAAE,KAAK,KAAK,EAAE;MACvEK,QAAQ,CAACC,KAAK,EAAEP,YAAY,CAAC;MAC7Bc,WAAW,CAACX,KAAK,IAAIiD,KAAK;MAC1BvB,aAAa,CAAC1B,KAAK,GAAG+C,gBAAgB;IACxC;EACF,CAAC,CAAC;EAEFxD,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX;MACAG,GAAG,CAACyD,OAAO,CAAClC,YAAY,CAAC,CAACb,KAAK,CAAC;IAClC,CAAC;EACH,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX,OAAO;IACLP,YAAY;IACZc,WAAW;IACXgB,QAAQ;IACRE,SAAS;IACTM,QAAQ;IACRJ;EACF,CAAC;AACH,CAAC"}
@@ -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
+ import { useEffect, useState } from "react";
2
+ import { createWorkletRuntime, runOnJS, runOnRuntime } from "react-native-reanimated";
3
+ import { Skia } from "../../skia";
4
+ const runtime = createWorkletRuntime("video-metadata-runtime");
5
+ export const useVideoLoading = source => {
6
+ const [video, setVideo] = useState(null);
7
+ const cb = src => {
8
+ "worklet";
9
+
10
+ const vid = Skia.Video(src);
11
+ runOnJS(setVideo)(vid);
12
+ };
13
+ useEffect(() => {
14
+ if (source) {
15
+ runOnRuntime(runtime, cb)(source);
16
+ }
17
+ }, [source]);
18
+ return video;
19
+ };
20
+ //# sourceMappingURL=useVideoLoading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useState","createWorkletRuntime","runOnJS","runOnRuntime","Skia","runtime","useVideoLoading","source","video","setVideo","cb","src","vid","Video"],"sources":["useVideoLoading.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport {\n createWorkletRuntime,\n runOnJS,\n runOnRuntime,\n} from \"react-native-reanimated\";\n\nimport type { Video } from \"../../skia/types\";\nimport { Skia } from \"../../skia\";\n\nconst runtime = 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 runOnJS(setVideo)(vid);\n };\n useEffect(() => {\n if (source) {\n runOnRuntime(runtime, cb)(source);\n }\n }, [source]);\n return video;\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SACEC,oBAAoB,EACpBC,OAAO,EACPC,YAAY,QACP,yBAAyB;AAGhC,SAASC,IAAI,QAAQ,YAAY;AAEjC,MAAMC,OAAO,GAAGJ,oBAAoB,CAAC,wBAAwB,CAAC;AAI9D,OAAO,MAAMK,eAAe,GAAIC,MAAmB,IAAK;EACtD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGT,QAAQ,CAAe,IAAI,CAAC;EACtD,MAAMU,EAAE,GAAIC,GAAW,IAAK;IAC1B,SAAS;;IACT,MAAMC,GAAG,GAAGR,IAAI,CAACS,KAAK,CAACF,GAAG,CAAU;IACpCT,OAAO,CAACO,QAAQ,CAAC,CAACG,GAAG,CAAC;EACxB,CAAC;EACDb,SAAS,CAAC,MAAM;IACd,IAAIQ,MAAM,EAAE;MACVJ,YAAY,CAACE,OAAO,EAAEK,EAAE,CAAC,CAACH,MAAM,CAAC;IACnC;EACF,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EACZ,OAAOC,KAAK;AACd,CAAC"}
@@ -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,13 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Skia } from "../../skia";
3
+ export const useVideoLoading = source => {
4
+ const [video, setVideo] = useState(null);
5
+ useEffect(() => {
6
+ if (source) {
7
+ const vid = Skia.Video(source);
8
+ vid.then(v => setVideo(v));
9
+ }
10
+ }, [source]);
11
+ return video;
12
+ };
13
+ //# sourceMappingURL=useVideoLoading.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useState","Skia","useVideoLoading","source","video","setVideo","vid","Video","then","v"],"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,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAG3C,SAASC,IAAI,QAAQ,YAAY;AAIjC,OAAO,MAAMC,eAAe,GAAIC,MAAmB,IAAK;EACtD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGL,QAAQ,CAAe,IAAI,CAAC;EACtDD,SAAS,CAAC,MAAM;IACd,IAAII,MAAM,EAAE;MACV,MAAMG,GAAG,GAAGL,IAAI,CAACM,KAAK,CAACJ,MAAM,CAAmB;MAChDG,GAAG,CAACE,IAAI,CAAEC,CAAC,IAAKJ,QAAQ,CAACI,CAAC,CAAC,CAAC;IAC9B;EACF,CAAC,EAAE,CAACN,MAAM,CAAC,CAAC;EACZ,OAAOC,KAAK;AACd,CAAC"}
@@ -1,21 +1,13 @@
1
1
  import type { ReactNode } from "react";
2
2
  import React from "react";
3
3
  import type { Fit } from "../../../dom/nodes";
4
- import type { SkRect } from "../../../skia/types";
4
+ import type { SkRect, Transforms3d } from "../../../skia/types";
5
5
  interface FitProps {
6
6
  fit?: Fit;
7
7
  src: SkRect;
8
8
  dst: SkRect;
9
9
  children: ReactNode | ReactNode[];
10
10
  }
11
- export declare const fitbox: (fit: Fit, src: SkRect, dst: SkRect) => [{
12
- translateX: number;
13
- }, {
14
- translateY: number;
15
- }, {
16
- scaleX: number;
17
- }, {
18
- scaleY: number;
19
- }];
11
+ export declare const fitbox: (fit: Fit, src: SkRect, dst: SkRect, rotation?: 0 | 90 | 180 | 270) => Transforms3d;
20
12
  export declare const FitBox: ({ fit, src, dst, children }: FitProps) => React.JSX.Element;
21
13
  export {};
@@ -1,9 +1,38 @@
1
1
  import React, { useMemo } from "react";
2
2
  import { fitRects, rect2rect } from "../../../dom/nodes";
3
3
  import { Group } from "../Group";
4
- export const fitbox = (fit, src, dst) => {
5
- const rects = fitRects(fit, src, dst);
6
- return rect2rect(rects.src, rects.dst);
4
+ export const fitbox = (fit, src, dst, rotation = 0) => {
5
+ "worklet";
6
+
7
+ const rects = fitRects(fit, rotation === 90 || rotation === 270 ? {
8
+ x: 0,
9
+ y: 0,
10
+ width: src.height,
11
+ height: src.width
12
+ } : src, dst);
13
+ const result = rect2rect(rects.src, rects.dst);
14
+ if (rotation === 90) {
15
+ return [...result, {
16
+ translate: [src.height, 0]
17
+ }, {
18
+ rotate: Math.PI / 2
19
+ }];
20
+ }
21
+ if (rotation === 180) {
22
+ return [...result, {
23
+ translate: [src.width, src.height]
24
+ }, {
25
+ rotate: Math.PI
26
+ }];
27
+ }
28
+ if (rotation === 270) {
29
+ return [...result, {
30
+ translate: [0, src.width]
31
+ }, {
32
+ rotate: -Math.PI / 2
33
+ }];
34
+ }
35
+ return result;
7
36
  };
8
37
  export const FitBox = ({
9
38
  fit = "contain",
@@ -1 +1 @@
1
- {"version":3,"names":["React","useMemo","fitRects","rect2rect","Group","fitbox","fit","src","dst","rects","FitBox","children","transform","createElement"],"sources":["FitBox.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport React, { useMemo } from \"react\";\n\nimport type { Fit } from \"../../../dom/nodes\";\nimport { fitRects, rect2rect } from \"../../../dom/nodes\";\nimport type { SkRect } from \"../../../skia/types\";\nimport { Group } from \"../Group\";\n\ninterface FitProps {\n fit?: Fit;\n src: SkRect;\n dst: SkRect;\n children: ReactNode | ReactNode[];\n}\n\nexport const fitbox = (fit: Fit, src: SkRect, dst: SkRect) => {\n const rects = fitRects(fit, src, dst);\n return rect2rect(rects.src, rects.dst);\n};\n\nexport const FitBox = ({ fit = \"contain\", src, dst, children }: FitProps) => {\n const transform = useMemo(() => fitbox(fit, src, dst), [dst, fit, src]);\n return <Group transform={transform}>{children}</Group>;\n};\n"],"mappings":"AACA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AAGtC,SAASC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AAExD,SAASC,KAAK,QAAQ,UAAU;AAShC,OAAO,MAAMC,MAAM,GAAGA,CAACC,GAAQ,EAAEC,GAAW,EAAEC,GAAW,KAAK;EAC5D,MAAMC,KAAK,GAAGP,QAAQ,CAACI,GAAG,EAAEC,GAAG,EAAEC,GAAG,CAAC;EACrC,OAAOL,SAAS,CAACM,KAAK,CAACF,GAAG,EAAEE,KAAK,CAACD,GAAG,CAAC;AACxC,CAAC;AAED,OAAO,MAAME,MAAM,GAAGA,CAAC;EAAEJ,GAAG,GAAG,SAAS;EAAEC,GAAG;EAAEC,GAAG;EAAEG;AAAmB,CAAC,KAAK;EAC3E,MAAMC,SAAS,GAAGX,OAAO,CAAC,MAAMI,MAAM,CAACC,GAAG,EAAEC,GAAG,EAAEC,GAAG,CAAC,EAAE,CAACA,GAAG,EAAEF,GAAG,EAAEC,GAAG,CAAC,CAAC;EACvE,oBAAOP,KAAA,CAAAa,aAAA,CAACT,KAAK;IAACQ,SAAS,EAAEA;EAAU,GAAED,QAAgB,CAAC;AACxD,CAAC"}
1
+ {"version":3,"names":["React","useMemo","fitRects","rect2rect","Group","fitbox","fit","src","dst","rotation","rects","x","y","width","height","result","translate","rotate","Math","PI","FitBox","children","transform","createElement"],"sources":["FitBox.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport React, { useMemo } from \"react\";\n\nimport type { Fit } from \"../../../dom/nodes\";\nimport { fitRects, rect2rect } from \"../../../dom/nodes\";\nimport type { SkRect, Transforms3d } from \"../../../skia/types\";\nimport { Group } from \"../Group\";\n\ninterface FitProps {\n fit?: Fit;\n src: SkRect;\n dst: SkRect;\n children: ReactNode | ReactNode[];\n}\n\nexport const fitbox = (\n fit: Fit,\n src: SkRect,\n dst: SkRect,\n rotation: 0 | 90 | 180 | 270 = 0\n) => {\n \"worklet\";\n const rects = fitRects(\n fit,\n rotation === 90 || rotation === 270\n ? { x: 0, y: 0, width: src.height, height: src.width }\n : src,\n dst\n );\n const result = rect2rect(rects.src, rects.dst);\n if (rotation === 90) {\n return [\n ...result,\n { translate: [src.height, 0] },\n { rotate: Math.PI / 2 },\n ] as Transforms3d;\n }\n if (rotation === 180) {\n return [\n ...result,\n { translate: [src.width, src.height] },\n { rotate: Math.PI },\n ] as Transforms3d;\n }\n if (rotation === 270) {\n return [\n ...result,\n { translate: [0, src.width] },\n { rotate: -Math.PI / 2 },\n ] as Transforms3d;\n }\n return result;\n};\n\nexport const FitBox = ({ fit = \"contain\", src, dst, children }: FitProps) => {\n const transform = useMemo(() => fitbox(fit, src, dst), [dst, fit, src]);\n return <Group transform={transform}>{children}</Group>;\n};\n"],"mappings":"AACA,OAAOA,KAAK,IAAIC,OAAO,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M;AACf,CAAC;AAED,OAAO,MAAMK,MAAM,GAAGA,CAAC;EAAEd,GAAG,GAAG,SAAS;EAAEC,GAAG;EAAEC,GAAG;EAAEa;AAAmB,CAAC,KAAK;EAC3E,MAAMC,SAAS,GAAGrB,OAAO,CAAC,MAAMI,MAAM,CAACC,GAAG,EAAEC,GAAG,EAAEC,GAAG,CAAC,EAAE,CAACA,GAAG,EAAEF,GAAG,EAAEC,GAAG,CAAC,CAAC;EACvE,oBAAOP,KAAA,CAAAuB,aAAA,CAACnB,KAAK;IAACkB,SAAS,EAAEA;EAAU,GAAED,QAAgB,CAAC;AACxD,CAAC"}
@@ -1,4 +1,8 @@
1
1
  import { Skia } from "../Skia";
2
2
  import { processTransform } from "../types";
3
- export const processTransform2d = transforms => processTransform(Skia.Matrix(), transforms);
3
+ export const processTransform2d = transforms => {
4
+ "worklet";
5
+
6
+ return processTransform(Skia.Matrix(), transforms);
7
+ };
4
8
  //# sourceMappingURL=Matrix.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Skia","processTransform","processTransform2d","transforms","Matrix"],"sources":["Matrix.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { Transforms3d } from \"../types\";\nimport { processTransform } from \"../types\";\n\nexport const processTransform2d = (transforms: Transforms3d) =>\n processTransform(Skia.Matrix(), transforms);\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,SAAS;AAE9B,SAASC,gBAAgB,QAAQ,UAAU;AAE3C,OAAO,MAAMC,kBAAkB,GAAIC,UAAwB,IACzDF,gBAAgB,CAACD,IAAI,CAACI,MAAM,CAAC,CAAC,EAAED,UAAU,CAAC"}
1
+ {"version":3,"names":["Skia","processTransform","processTransform2d","transforms","Matrix"],"sources":["Matrix.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { Transforms3d } from \"../types\";\nimport { processTransform } from \"../types\";\n\nexport const processTransform2d = (transforms: Transforms3d) => {\n \"worklet\";\n return processTransform(Skia.Matrix(), transforms);\n};\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,SAAS;AAE9B,SAASC,gBAAgB,QAAQ,UAAU;AAE3C,OAAO,MAAMC,kBAAkB,GAAIC,UAAwB,IAAK;EAC9D,SAAS;;EACT,OAAOF,gBAAgB,CAACD,IAAI,CAACI,MAAM,CAAC,CAAC,EAAED,UAAU,CAAC;AACpD,CAAC"}
@@ -1,6 +1,8 @@
1
1
  import { processTransform3d } from "./Matrix4";
2
2
  export const isMatrix = obj => obj !== null && obj.__typename__ === "Matrix";
3
3
  export const processTransform = (m, transforms) => {
4
+ "worklet";
5
+
4
6
  const m3 = processTransform3d(transforms);
5
7
  m.concat(m3);
6
8
  return m;
@@ -1 +1 @@
1
- {"version":3,"names":["processTransform3d","isMatrix","obj","__typename__","processTransform","m","transforms","m3","concat","toDegrees","rad","Math","PI"],"sources":["Matrix.ts"],"sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nimport type { Matrix3, Matrix4, Transforms3d } from \"./Matrix4\";\nimport { processTransform3d } from \"./Matrix4\";\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: InputMatrix) => SkMatrix;\n translate: (x: number, y: number) => SkMatrix;\n scale: (x: number, y?: number) => SkMatrix;\n skew: (x: number, y: number) => SkMatrix;\n rotate: (theta: number) => SkMatrix;\n postTranslate: (x: number, y: number) => SkMatrix;\n postScale: (x: number, y?: number) => SkMatrix;\n postSkew: (x: number, y: number) => SkMatrix;\n postRotate: (theta: number) => SkMatrix;\n identity: () => SkMatrix;\n get: () => number[];\n}\n\nexport type InputMatrix = SkMatrix | Matrix3 | Matrix4 | number[];\n\nexport interface TransformProp {\n transform?: Transforms3d;\n}\n\nexport const processTransform = <T extends SkMatrix | SkCanvas>(\n m: T,\n transforms: Transforms3d\n) => {\n const m3 = processTransform3d(transforms);\n m.concat(m3);\n return m;\n};\n\nexport const toDegrees = (rad: number) => {\n return (rad * 180) / Math.PI;\n};\n"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,WAAW;AAE9C,OAAO,MAAMC,QAAQ,GAAIC,GAAY,IACnCA,GAAG,KAAK,IAAI,IAAKA,GAAG,CAA2BC,YAAY,KAAK,QAAQ;AAsB1E,OAAO,MAAMC,gBAAgB,GAAGA,CAC9BC,CAAI,EACJC,UAAwB,KACrB;EACH,MAAMC,EAAE,GAAGP,kBAAkB,CAACM,UAAU,CAAC;EACzCD,CAAC,CAACG,MAAM,CAACD,EAAE,CAAC;EACZ,OAAOF,CAAC;AACV,CAAC;AAED,OAAO,MAAMI,SAAS,GAAIC,GAAW,IAAK;EACxC,OAAQA,GAAG,GAAG,GAAG,GAAIC,IAAI,CAACC,EAAE;AAC9B,CAAC"}
1
+ {"version":3,"names":["processTransform3d","isMatrix","obj","__typename__","processTransform","m","transforms","m3","concat","toDegrees","rad","Math","PI"],"sources":["Matrix.ts"],"sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nimport type { Matrix3, Matrix4, Transforms3d } from \"./Matrix4\";\nimport { processTransform3d } from \"./Matrix4\";\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: InputMatrix) => SkMatrix;\n translate: (x: number, y: number) => SkMatrix;\n scale: (x: number, y?: number) => SkMatrix;\n skew: (x: number, y: number) => SkMatrix;\n rotate: (theta: number) => SkMatrix;\n postTranslate: (x: number, y: number) => SkMatrix;\n postScale: (x: number, y?: number) => SkMatrix;\n postSkew: (x: number, y: number) => SkMatrix;\n postRotate: (theta: number) => SkMatrix;\n identity: () => SkMatrix;\n get: () => number[];\n}\n\nexport type InputMatrix = SkMatrix | Matrix3 | Matrix4 | number[];\n\nexport interface TransformProp {\n transform?: Transforms3d;\n}\n\nexport const processTransform = <T extends SkMatrix | SkCanvas>(\n m: T,\n transforms: Transforms3d\n) => {\n \"worklet\";\n const m3 = processTransform3d(transforms);\n m.concat(m3);\n return m;\n};\n\nexport const toDegrees = (rad: number) => {\n return (rad * 180) / Math.PI;\n};\n"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,WAAW;AAE9C,OAAO,MAAMC,QAAQ,GAAIC,GAAY,IACnCA,GAAG,KAAK,IAAI,IAAKA,GAAG,CAA2BC,YAAY,KAAK,QAAQ;AAsB1E,OAAO,MAAMC,gBAAgB,GAAGA,CAC9BC,CAAI,EACJC,UAAwB,KACrB;EACH,SAAS;;EACT,MAAMC,EAAE,GAAGP,kBAAkB,CAACM,UAAU,CAAC;EACzCD,CAAC,CAACG,MAAM,CAACD,EAAE,CAAC;EACZ,OAAOF,CAAC;AACV,CAAC;AAED,OAAO,MAAMI,SAAS,GAAIC,GAAW,IAAK;EACxC,OAAQA,GAAG,GAAG,GAAG,GAAIC,IAAI,CAACC,EAAE;AAC9B,CAAC"}
@@ -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>;
@@ -1,4 +1,5 @@
1
+ export class CanvasKitWebGLBuffer {}
1
2
  export const isNativeBufferAddr = buffer => buffer instanceof BigInt;
2
- export const isNativeBufferWeb = buffer => buffer instanceof HTMLVideoElement || buffer instanceof HTMLCanvasElement || buffer instanceof ImageBitmap || buffer instanceof OffscreenCanvas || buffer instanceof VideoFrame || buffer instanceof HTMLImageElement || buffer instanceof SVGImageElement;
3
+ export 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;
3
4
  export const isNativeBufferNode = buffer => buffer instanceof ArrayBuffer;
4
5
  //# sourceMappingURL=NativeBufferFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["isNativeBufferAddr","buffer","BigInt","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":"AAUA,OAAO,MAAMA,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AACzD,OAAO,MAAMC,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;AAEnC,OAAO,MAAMC,kBAAkB,GAC7BV,MAAoB,IACWA,MAAM,YAAYW,WAAW"}
1
+ {"version":3,"names":["CanvasKitWebGLBuffer","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":"AAEA,OAAO,MAAeA,oBAAoB,CAAC;AAe3C,OAAO,MAAMC,kBAAkB,GAC7BC,MAAoB,IACWA,MAAM,YAAYC,MAAM;AACzD,OAAO,MAAMC,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,YAAYF,oBAAoB;AAExC,OAAO,MAAMY,kBAAkB,GAC7BV,MAAoB,IACWA,MAAM,YAAYW,WAAW"}
@@ -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":""}
@@ -1,9 +1,17 @@
1
1
  import type { SkImage } from "../Image";
2
2
  import type { SkJSIInstance } from "../JsiInstance";
3
+ export type VideoRotation = 0 | 90 | 180 | 270;
3
4
  export interface Video extends SkJSIInstance<"Video"> {
4
5
  duration(): number;
5
6
  framerate(): number;
6
7
  nextImage(): SkImage | null;
7
8
  seek(time: number): void;
8
- getRotationInDegrees(): number;
9
+ rotation(): VideoRotation;
10
+ size(): {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ pause(): void;
15
+ play(): void;
16
+ setVolume(volume: number): void;
9
17
  }
@@ -1 +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 getRotationInDegrees(): number;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["Video.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\n\nexport type VideoRotation = 0 | 90 | 180 | 270;\n\nexport interface Video extends SkJSIInstance<\"Video\"> {\n duration(): number;\n framerate(): number;\n nextImage(): SkImage | null;\n seek(time: number): void;\n rotation(): VideoRotation;\n size(): { width: number; height: number };\n pause(): void;\n play(): void;\n setVolume(volume: number): void;\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,23 @@
1
+ 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; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
3
+ 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); }
4
+ import { CanvasKitWebGLBuffer } from "../types";
5
+ export class CanvasKitWebGLBufferImpl extends CanvasKitWebGLBuffer {
6
+ constructor(surface, source) {
7
+ super();
8
+ this.surface = surface;
9
+ this.source = source;
10
+ _defineProperty(this, "image", null);
11
+ }
12
+ toImage() {
13
+ if (this.image === null) {
14
+ this.image = this.surface.makeImageFromTextureSource(this.source);
15
+ }
16
+ if (this.image === null) {
17
+ throw new Error("Failed to create image from texture source");
18
+ }
19
+ this.surface.updateTextureFromSource(this.image, this.source);
20
+ return this.image;
21
+ }
22
+ }
23
+ //# sourceMappingURL=CanvasKitWebGLBufferImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CanvasKitWebGLBuffer","CanvasKitWebGLBufferImpl","constructor","surface","source","_defineProperty","toImage","image","makeImageFromTextureSource","Error","updateTextureFromSource"],"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,SAASA,oBAAoB,QAAQ,UAAU;AAE/C,OAAO,MAAMC,wBAAwB,SAASD,oBAAoB,CAAC;EAGjEE,WAAWA,CAAQC,OAAgB,EAAUC,MAAqB,EAAE;IAClE,KAAK,CAAC,CAAC;IAAC,KADSD,OAAgB,GAAhBA,OAAgB;IAAA,KAAUC,MAAqB,GAArBA,MAAqB;IAAAC,eAAA,gBAFrC,IAAI;EAIjC;EAEAC,OAAOA,CAAA,EAAG;IACR,IAAI,IAAI,CAACC,KAAK,KAAK,IAAI,EAAE;MACvB,IAAI,CAACA,KAAK,GAAG,IAAI,CAACJ,OAAO,CAACK,0BAA0B,CAAC,IAAI,CAACJ,MAAM,CAAC;IACnE;IACA,IAAI,IAAI,CAACG,KAAK,KAAK,IAAI,EAAE;MACvB,MAAM,IAAIE,KAAK,CAAC,4CAA4C,CAAC;IAC/D;IACA,IAAI,CAACN,OAAO,CAACO,uBAAuB,CAAC,IAAI,CAACH,KAAK,EAAE,IAAI,CAACH,MAAM,CAAC;IAC7D,OAAO,IAAI,CAACG,KAAK;EACnB;AACF"}
@@ -1,4 +1,4 @@
1
- import { isNativeBufferWeb } from "../types";
1
+ import { CanvasKitWebGLBuffer, isNativeBufferWeb } from "../types";
2
2
  import { Host, getEnum } from "./Host";
3
3
  import { JsiSkImage } from "./JsiSkImage";
4
4
  import { JsiSkData } from "./JsiSkData";
@@ -17,8 +17,14 @@ export class JsiSkImageFactory extends Host {
17
17
  throw new Error("Invalid NativeBuffer");
18
18
  }
19
19
  if (!surface) {
20
- // TODO: this is way to slow
21
- const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
20
+ let img;
21
+ if (buffer instanceof HTMLImageElement || buffer instanceof HTMLVideoElement || buffer instanceof ImageBitmap) {
22
+ img = this.CanvasKit.MakeLazyImageFromTextureSource(buffer);
23
+ } else if (buffer instanceof CanvasKitWebGLBuffer) {
24
+ img = buffer.toImage();
25
+ } else {
26
+ img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
27
+ }
22
28
  return new JsiSkImage(this.CanvasKit, img);
23
29
  } else if (!image) {
24
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1 +1 @@
1
- {"version":3,"names":["isNativeBufferWeb","Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromNativeBuffer","buffer","surface","image","Error","img","MakeImageFromCanvasImageSource","makeImageFromTextureSource","updateTextureFromSource","MakeImageFromEncoded","encoded","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit, Image } from \"canvaskit-wasm\";\n\nimport { isNativeBufferWeb } from \"../types\";\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n NativeBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\nimport type { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromNativeBuffer(\n buffer: NativeBuffer,\n surface?: JsiSkSurface,\n image?: JsiSkImage\n ) {\n if (!isNativeBufferWeb(buffer)) {\n throw new Error(\"Invalid NativeBuffer\");\n }\n if (!surface) {\n // TODO: this is way to slow\n const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);\n return new JsiSkImage(this.CanvasKit, img);\n } else if (!image) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).makeImageFromTextureSource(buffer) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).updateTextureFromSource(\n image,\n buffer\n ) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n }\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: getEnum(this.CanvasKit.ColorType, info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,UAAU;AAS5C,SAASC,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AACtC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAGvC,OAAO,MAAMC,iBAAiB,SAASJ,IAAI,CAAyB;EAClEK,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EACl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5D;IACA,MAAMZ,KAAK,GAAG,IAAI,CAACX,SAAS,CAACoB,SAAS,CACpC;MACEI,SAAS,EAAE7B,OAAO,CAAC,IAAI,CAACK,SAAS,CAACyB,SAAS,EAAEJ,IAAI,CAACG,SAAS,CAAC;MAC5DE,UAAU,EAAE,IAAI,CAAC1B,SAAS,CAAC2B,UAAU,CAACC,IAAI;MAC1CC,SAAS,EAAElC,OAAO,CAAC,IAAI,CAACK,SAAS,CAAC8B,SAAS,EAAET,IAAI,CAACQ,SAAS,CAAC;MAC5DE,MAAM,EAAEV,IAAI,CAACU,MAAM;MACnBC,KAAK,EAAEX,IAAI,CAACW;IACd,CAAC,EACDnC,SAAS,CAACsB,SAAS,CAACG,IAAI,CAAC,EACzBC,WACF,CAAC;IACD,IAAIZ,KAAK,KAAK,IAAI,EAAE;MAClB,OAAO,IAAI;IACb;IACA,OAAO,IAAIf,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEW,KAAK,CAAC;EAC9C;AACF"}
1
+ {"version":3,"names":["CanvasKitWebGLBuffer","isNativeBufferWeb","Host","getEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromNativeBuffer","buffer","surface","image","Error","img","HTMLImageElement","HTMLVideoElement","ImageBitmap","MakeLazyImageFromTextureSource","toImage","MakeImageFromCanvasImageSource","makeImageFromTextureSource","updateTextureFromSource","MakeImageFromEncoded","encoded","fromValue","MakeImage","info","data","bytesPerRow","alphaType","AlphaType","colorSpace","ColorSpace","SRGB","colorType","ColorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit, Image } from \"canvaskit-wasm\";\n\nimport { CanvasKitWebGLBuffer, isNativeBufferWeb } from \"../types\";\nimport type {\n SkData,\n ImageInfo,\n SkImage,\n NativeBuffer,\n ImageFactory,\n} from \"../types\";\n\nimport { Host, getEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\nimport type { JsiSkSurface } from \"./JsiSkSurface\";\nimport type { CanvasKitWebGLBufferImpl } from \"./CanvasKitWebGLBufferImpl\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromNativeBuffer(\n buffer: NativeBuffer,\n surface?: JsiSkSurface,\n image?: JsiSkImage\n ) {\n if (!isNativeBufferWeb(buffer)) {\n throw new Error(\"Invalid NativeBuffer\");\n }\n if (!surface) {\n let img: Image;\n if (\n buffer instanceof HTMLImageElement ||\n buffer instanceof HTMLVideoElement ||\n buffer instanceof ImageBitmap\n ) {\n img = this.CanvasKit.MakeLazyImageFromTextureSource(buffer);\n } else if (buffer instanceof CanvasKitWebGLBuffer) {\n img = (\n buffer as CanvasKitWebGLBuffer as CanvasKitWebGLBufferImpl\n ).toImage();\n } else {\n img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);\n }\n return new JsiSkImage(this.CanvasKit, img);\n } else if (!image) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).makeImageFromTextureSource(buffer) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const img = (surface as any).updateTextureFromSource(\n image,\n buffer\n ) as Image;\n return new JsiSkImage(this.CanvasKit, img);\n }\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: getEnum(this.CanvasKit.AlphaType, info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: getEnum(this.CanvasKit.ColorType, info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"AAEA,SAASA,oBAAoB,EAAEC,iBAAiB,QAAQ,UAAU;AASlE,SAASC,IAAI,EAAEC,OAAO,QAAQ,QAAQ;AACtC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAIvC,OAAO,MAAMC,iBAAiB,SAASJ,IAAI,CAAyB;EAClEK,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,oBAAoBA,CAACC,OAAe,EAA2B;IAC7D,MAAMC,IAAI,GAAGD,OAAiC;IAC9C;IACAE,OAAO,CAACC,GAAG,CAACF,IAAI,CAAC;IACjB,OAAOG,OAAO,CAACC,OAAO,CAAC,IAAI,CAAC;EAC9B;EAEAC,yBAAyBA,CACvBC,MAAoB,EACpBC,OAAsB,EACtBC,KAAkB,EAClB;IACA,IAAI,CAAClB,iBAAiB,CAACgB,MAAM,CAAC,EAAE;MAC9B,MAAM,IAAIG,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,IAAI,CAACF,OAAO,EAAE;MACZ,IAAIG,GAAU;MACd,IACEJ,MAAM,YAAYK,gBAAgB,IAClCL,MAAM,YAAYM,gBAAgB,IAClCN,MAAM,YAAYO,WAAW,EAC7B;QACAH,GAAG,GAAG,IAAI,CAACb,SAAS,CAACiB,8BAA8B,CAACR,MAAM,CAAC;MAC7D,CAAC,MAAM,IAAIA,MAAM,YAAYjB,oBAAoB,EAAE;QACjDqB,GAAG,GACDJ,MAAM,CACNS,OAAO,CAAC,CAAC;MACb,CAAC,MAAM;QACLL,GAAG,GAAG,IAAI,CAACb,SAAS,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SAAS,CAAC2B,SAAS,CAACG,IAAI,CAAC,EACzBC,WACF,CAAC;IACD,IAAIjB,KAAK,KAAK,IAAI,EAAE;MAClB,OAAO,IAAI;IACb;IACA,OAAO,IAAIf,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEW,KAAK,CAAC;EAC9C;AACF"}
@@ -30,6 +30,7 @@ import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
30
30
  import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
31
31
  import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
32
32
  import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
33
+ import { createVideo } from "./JsiVideo";
33
34
  export const JsiSkApi = CanvasKit => ({
34
35
  Point: (x, y) => new JsiSkPoint(CanvasKit, Float32Array.of(x, y)),
35
36
  RuntimeShaderBuilder: _ => {
@@ -75,8 +76,6 @@ export const JsiSkApi = CanvasKit => ({
75
76
  FontMgr: new JsiSkFontMgrFactory(CanvasKit),
76
77
  ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
77
78
  NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
78
- Video: _localUri => {
79
- throw new Error("Not implemented on React Native Web");
80
- }
79
+ Video: createVideo.bind(null, CanvasKit)
81
80
  });
82
81
  //# sourceMappingURL=JsiSkia.js.map