@shopify/react-native-skia 1.3.1 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +72 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.h +5 -0
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkVideo.java +89 -8
- package/cpp/api/JsiVideo.h +37 -5
- package/cpp/rnskia/RNSkVideo.h +5 -0
- package/ios/RNSkia-iOS/RNSkiOSVideo.h +14 -3
- package/ios/RNSkia-iOS/RNSkiOSVideo.mm +78 -60
- package/lib/commonjs/dom/nodes/datatypes/Fitting.js +42 -30
- package/lib/commonjs/dom/nodes/datatypes/Fitting.js.map +1 -1
- package/lib/commonjs/external/reanimated/useVideo.d.ts +14 -5
- package/lib/commonjs/external/reanimated/useVideo.js +90 -58
- package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/FitBox.d.ts +2 -10
- package/lib/commonjs/renderer/components/shapes/FitBox.js +32 -3
- package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/commonjs/skia/core/Matrix.js +5 -1
- package/lib/commonjs/skia/core/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.js +2 -0
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Video/Video.d.ts +9 -0
- package/lib/commonjs/skia/types/Video/Video.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Fitting.js +41 -29
- package/lib/module/dom/nodes/datatypes/Fitting.js.map +1 -1
- package/lib/module/external/reanimated/useVideo.d.ts +14 -5
- package/lib/module/external/reanimated/useVideo.js +91 -59
- package/lib/module/external/reanimated/useVideo.js.map +1 -1
- package/lib/module/renderer/components/shapes/FitBox.d.ts +2 -10
- package/lib/module/renderer/components/shapes/FitBox.js +32 -3
- package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/module/skia/core/Matrix.js +5 -1
- package/lib/module/skia/core/Matrix.js.map +1 -1
- package/lib/module/skia/types/Matrix.js +2 -0
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/Video/Video.d.ts +9 -0
- package/lib/module/skia/types/Video/Video.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/typescript/src/external/reanimated/useVideo.d.ts +14 -5
- package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +2 -10
- package/lib/typescript/src/skia/types/Video/Video.d.ts +9 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/dom/nodes/datatypes/Fitting.ts +28 -21
- package/src/external/reanimated/useVideo.ts +86 -73
- package/src/renderer/components/shapes/FitBox.tsx +38 -4
- package/src/skia/core/Matrix.ts +4 -2
- package/src/skia/types/Matrix.ts +1 -0
- package/src/skia/types/Video/Video.ts +7 -0
- package/src/skia/types/index.ts +1 -0
@@ -1,9 +1,15 @@
|
|
1
1
|
import { exhaustiveCheck } from "../../../renderer/typeddash";
|
2
|
-
export const size = (width = 0, height = 0) =>
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
export const size = (width = 0, height = 0) => {
|
3
|
+
"worklet";
|
4
|
+
|
5
|
+
return {
|
6
|
+
width,
|
7
|
+
height
|
8
|
+
};
|
9
|
+
};
|
6
10
|
export const rect2rect = (src, dst) => {
|
11
|
+
"worklet";
|
12
|
+
|
7
13
|
const scaleX = dst.width / src.width;
|
8
14
|
const scaleY = dst.height / src.height;
|
9
15
|
const translateX = dst.x - src.x * scaleX;
|
@@ -18,35 +24,12 @@ export const rect2rect = (src, dst) => {
|
|
18
24
|
scaleY
|
19
25
|
}];
|
20
26
|
};
|
21
|
-
export const fitRects = (fit, rect, {
|
22
|
-
x,
|
23
|
-
y,
|
24
|
-
width,
|
25
|
-
height
|
26
|
-
}) => {
|
27
|
-
const sizes = applyBoxFit(fit, {
|
28
|
-
width: rect.width,
|
29
|
-
height: rect.height
|
30
|
-
}, {
|
31
|
-
width,
|
32
|
-
height
|
33
|
-
});
|
34
|
-
const src = inscribe(sizes.src, rect);
|
35
|
-
const dst = inscribe(sizes.dst, {
|
36
|
-
x,
|
37
|
-
y,
|
38
|
-
width,
|
39
|
-
height
|
40
|
-
});
|
41
|
-
return {
|
42
|
-
src,
|
43
|
-
dst
|
44
|
-
};
|
45
|
-
};
|
46
27
|
const inscribe = ({
|
47
28
|
width,
|
48
29
|
height
|
49
30
|
}, rect) => {
|
31
|
+
"worklet";
|
32
|
+
|
50
33
|
const halfWidthDelta = (rect.width - width) / 2.0;
|
51
34
|
const halfHeightDelta = (rect.height - height) / 2.0;
|
52
35
|
return {
|
@@ -57,6 +40,8 @@ const inscribe = ({
|
|
57
40
|
};
|
58
41
|
};
|
59
42
|
const applyBoxFit = (fit, input, output) => {
|
43
|
+
"worklet";
|
44
|
+
|
60
45
|
let src = size(),
|
61
46
|
dst = size();
|
62
47
|
if (input.height <= 0.0 || input.width <= 0.0 || output.height <= 0.0 || output.width <= 0.0) {
|
@@ -117,4 +102,31 @@ const applyBoxFit = (fit, input, output) => {
|
|
117
102
|
dst
|
118
103
|
};
|
119
104
|
};
|
105
|
+
export const fitRects = (fit, rect, {
|
106
|
+
x,
|
107
|
+
y,
|
108
|
+
width,
|
109
|
+
height
|
110
|
+
}) => {
|
111
|
+
"worklet";
|
112
|
+
|
113
|
+
const sizes = applyBoxFit(fit, {
|
114
|
+
width: rect.width,
|
115
|
+
height: rect.height
|
116
|
+
}, {
|
117
|
+
width,
|
118
|
+
height
|
119
|
+
});
|
120
|
+
const src = inscribe(sizes.src, rect);
|
121
|
+
const dst = inscribe(sizes.dst, {
|
122
|
+
x,
|
123
|
+
y,
|
124
|
+
width,
|
125
|
+
height
|
126
|
+
});
|
127
|
+
return {
|
128
|
+
src,
|
129
|
+
dst
|
130
|
+
};
|
131
|
+
};
|
120
132
|
//# sourceMappingURL=Fitting.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["exhaustiveCheck","size","width","height","rect2rect","src","dst","scaleX","scaleY","translateX","x","translateY","y","
|
1
|
+
{"version":3,"names":["exhaustiveCheck","size","width","height","rect2rect","src","dst","scaleX","scaleY","translateX","x","translateY","y","inscribe","rect","halfWidthDelta","halfHeightDelta","applyBoxFit","fit","input","output","Math","min","aspectRatio","fitRects","sizes"],"sources":["Fitting.ts"],"sourcesContent":["import { exhaustiveCheck } from \"../../../renderer/typeddash\";\nimport type { SkRect } from \"../../../skia/types\";\nimport type { Fit } from \"../../types\";\n\nexport interface Size {\n width: number;\n height: number;\n}\n\nexport const size = (width = 0, height = 0) => {\n \"worklet\";\n return { width, height };\n};\n\nexport const rect2rect = (\n src: SkRect,\n dst: SkRect\n): [\n { translateX: number },\n { translateY: number },\n { scaleX: number },\n { scaleY: number }\n] => {\n \"worklet\";\n const scaleX = dst.width / src.width;\n const scaleY = dst.height / src.height;\n const translateX = dst.x - src.x * scaleX;\n const translateY = dst.y - src.y * scaleY;\n return [{ translateX }, { translateY }, { scaleX }, { scaleY }];\n};\n\nconst inscribe = (\n { width, height }: Size,\n rect: { x: number; y: number; width: number; height: number }\n) => {\n \"worklet\";\n const halfWidthDelta = (rect.width - width) / 2.0;\n const halfHeightDelta = (rect.height - height) / 2.0;\n return {\n x: rect.x + halfWidthDelta,\n y: rect.y + halfHeightDelta,\n width,\n height,\n };\n};\n\nconst applyBoxFit = (fit: Fit, input: Size, output: Size) => {\n \"worklet\";\n let src = size(),\n dst = size();\n if (\n input.height <= 0.0 ||\n input.width <= 0.0 ||\n output.height <= 0.0 ||\n output.width <= 0.0\n ) {\n return { src, dst };\n }\n switch (fit) {\n case \"fill\":\n src = input;\n dst = output;\n break;\n case \"contain\":\n src = input;\n if (output.width / output.height > src.width / src.height) {\n dst = size((src.width * output.height) / src.height, output.height);\n } else {\n dst = size(output.width, (src.height * output.width) / src.width);\n }\n break;\n case \"cover\":\n if (output.width / output.height > input.width / input.height) {\n src = size(input.width, (input.width * output.height) / output.width);\n } else {\n src = size((input.height * output.width) / output.height, input.height);\n }\n dst = output;\n break;\n case \"fitWidth\":\n src = size(input.width, (input.width * output.height) / output.width);\n dst = size(output.width, (src.height * output.width) / src.width);\n break;\n case \"fitHeight\":\n src = size((input.height * output.width) / output.height, input.height);\n dst = size((src.width * output.height) / src.height, output.height);\n break;\n case \"none\":\n src = size(\n Math.min(input.width, output.width),\n Math.min(input.height, output.height)\n );\n dst = src;\n break;\n case \"scaleDown\":\n src = input;\n dst = input;\n const aspectRatio = input.width / input.height;\n if (dst.height > output.height) {\n dst = size(output.height * aspectRatio, output.height);\n }\n if (dst.width > output.width) {\n dst = size(output.width, output.width / aspectRatio);\n }\n break;\n default:\n exhaustiveCheck(fit);\n }\n return { src, dst };\n};\n\nexport const fitRects = (\n fit: Fit,\n rect: SkRect,\n { x, y, width, height }: SkRect\n) => {\n \"worklet\";\n const sizes = applyBoxFit(\n fit,\n { width: rect.width, height: rect.height },\n { width, height }\n );\n const src = inscribe(sizes.src, rect);\n const dst = inscribe(sizes.dst, {\n x,\n y,\n width,\n height,\n });\n return { src, dst };\n};\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,6BAA6B;AAS7D,OAAO,MAAMC,IAAI,GAAGA,CAACC,KAAK,GAAG,CAAC,EAAEC,MAAM,GAAG,CAAC,KAAK;EAC7C,SAAS;;EACT,OAAO;IAAED,KAAK;IAAEC;EAAO,CAAC;AAC1B,CAAC;AAED,OAAO,MAAMC,SAAS,GAAGA,CACvBC,GAAW,EACXC,GAAW,KAMR;EACH,SAAS;;EACT,MAAMC,MAAM,GAAGD,GAAG,CAACJ,KAAK,GAAGG,GAAG,CAACH,KAAK;EACpC,MAAMM,MAAM,GAAGF,GAAG,CAACH,MAAM,GAAGE,GAAG,CAACF,MAAM;EACtC,MAAMM,UAA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AS;;EACT,MAAMsB,KAAK,GAAGR,WAAW,CACvBC,GAAG,EACH;IAAEhB,KAAK,EAAEY,IAAI,CAACZ,KAAK;IAAEC,MAAM,EAAEW,IAAI,CAACX;EAAO,CAAC,EAC1C;IAAED,KAAK;IAAEC;EAAO,CAClB,CAAC;EACD,MAAME,GAAG,GAAGQ,QAAQ,CAACY,KAAK,CAACpB,GAAG,EAAES,IAAI,CAAC;EACrC,MAAMR,GAAG,GAAGO,QAAQ,CAACY,KAAK,CAACnB,GAAG,EAAE;IAC9BI,CAAC;IACDE,CAAC;IACDV,KAAK;IACLC;EACF,CAAC,CAAC;EACF,OAAO;IAAEE,GAAG;IAAEC;EAAI,CAAC;AACrB,CAAC"}
|
@@ -1,12 +1,21 @@
|
|
1
|
-
import {
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
2
|
import type { SkImage } from "../../skia/types";
|
3
3
|
type Animated<T> = SharedValue<T> | T;
|
4
|
-
|
5
|
-
playbackSpeed: Animated<number>;
|
4
|
+
interface PlaybackOptions {
|
6
5
|
looping: Animated<boolean>;
|
7
6
|
paused: Animated<boolean>;
|
8
7
|
seek: Animated<number | null>;
|
9
|
-
|
8
|
+
volume: Animated<number>;
|
10
9
|
}
|
11
|
-
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) =>
|
10
|
+
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => {
|
11
|
+
currentFrame: SharedValue<SkImage | null>;
|
12
|
+
currentTime: SharedValue<number>;
|
13
|
+
duration: number;
|
14
|
+
framerate: number;
|
15
|
+
rotation: import("../../skia/types").VideoRotation;
|
16
|
+
size: {
|
17
|
+
width: number;
|
18
|
+
height: number;
|
19
|
+
};
|
20
|
+
};
|
12
21
|
export {};
|
@@ -1,97 +1,129 @@
|
|
1
|
-
import {
|
2
|
-
import { useCallback, useEffect, useMemo } from "react";
|
1
|
+
import { useEffect, useMemo } from "react";
|
3
2
|
import { Skia } from "../../skia/Skia";
|
4
3
|
import { Platform } from "../../Platform";
|
5
4
|
import Rea from "./ReanimatedProxy";
|
5
|
+
const setFrame = (video, currentFrame) => {
|
6
|
+
"worklet";
|
7
|
+
|
8
|
+
const img = video.nextImage();
|
9
|
+
if (img) {
|
10
|
+
if (currentFrame.value) {
|
11
|
+
currentFrame.value.dispose();
|
12
|
+
}
|
13
|
+
if (Platform.OS === "android") {
|
14
|
+
currentFrame.value = img.makeNonTextureImage();
|
15
|
+
} else {
|
16
|
+
currentFrame.value = img;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
};
|
6
20
|
const defaultOptions = {
|
7
|
-
playbackSpeed: 1,
|
8
21
|
looping: true,
|
9
22
|
paused: false,
|
10
23
|
seek: null,
|
11
|
-
currentTime: 0
|
24
|
+
currentTime: 0,
|
25
|
+
volume: 0
|
12
26
|
};
|
13
27
|
const useOption = value => {
|
14
28
|
"worklet";
|
15
29
|
|
16
30
|
// TODO: only create defaultValue is needed (via makeMutable)
|
17
|
-
const defaultValue = useSharedValue(Rea.isSharedValue(value) ? value.value : value);
|
31
|
+
const defaultValue = Rea.useSharedValue(Rea.isSharedValue(value) ? value.value : value);
|
18
32
|
return Rea.isSharedValue(value) ? value : defaultValue;
|
19
33
|
};
|
34
|
+
const disposeVideo = video => {
|
35
|
+
"worklet";
|
36
|
+
|
37
|
+
video === null || video === void 0 || video.dispose();
|
38
|
+
};
|
20
39
|
export const useVideo = (source, userOptions) => {
|
21
|
-
var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$
|
40
|
+
var _userOptions$paused, _userOptions$looping, _userOptions$seek, _userOptions$volume;
|
22
41
|
const video = useMemo(() => source ? Skia.Video(source) : null, [source]);
|
23
42
|
const isPaused = useOption((_userOptions$paused = userOptions === null || userOptions === void 0 ? void 0 : userOptions.paused) !== null && _userOptions$paused !== void 0 ? _userOptions$paused : defaultOptions.paused);
|
24
43
|
const looping = useOption((_userOptions$looping = userOptions === null || userOptions === void 0 ? void 0 : userOptions.looping) !== null && _userOptions$looping !== void 0 ? _userOptions$looping : defaultOptions.looping);
|
25
44
|
const seek = useOption((_userOptions$seek = userOptions === null || userOptions === void 0 ? void 0 : userOptions.seek) !== null && _userOptions$seek !== void 0 ? _userOptions$seek : defaultOptions.seek);
|
26
|
-
const
|
27
|
-
const playbackSpeed = useOption((_userOptions$playback = userOptions === null || userOptions === void 0 ? void 0 : userOptions.playbackSpeed) !== null && _userOptions$playback !== void 0 ? _userOptions$playback : defaultOptions.playbackSpeed);
|
45
|
+
const volume = useOption((_userOptions$volume = userOptions === null || userOptions === void 0 ? void 0 : userOptions.volume) !== null && _userOptions$volume !== void 0 ? _userOptions$volume : defaultOptions.volume);
|
28
46
|
const currentFrame = Rea.useSharedValue(null);
|
47
|
+
const currentTime = Rea.useSharedValue(0);
|
29
48
|
const lastTimestamp = Rea.useSharedValue(-1);
|
30
|
-
const
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
const
|
35
|
-
|
36
|
-
|
37
|
-
|
49
|
+
const duration = useMemo(() => {
|
50
|
+
var _video$duration;
|
51
|
+
return (_video$duration = video === null || video === void 0 ? void 0 : video.duration()) !== null && _video$duration !== void 0 ? _video$duration : 0;
|
52
|
+
}, [video]);
|
53
|
+
const framerate = useMemo(() => {
|
54
|
+
var _video$framerate;
|
55
|
+
return (_video$framerate = video === null || video === void 0 ? void 0 : video.framerate()) !== null && _video$framerate !== void 0 ? _video$framerate : 0;
|
56
|
+
}, [video]);
|
57
|
+
const size = useMemo(() => {
|
58
|
+
var _video$size;
|
59
|
+
return (_video$size = video === null || video === void 0 ? void 0 : video.size()) !== null && _video$size !== void 0 ? _video$size : {
|
60
|
+
width: 0,
|
61
|
+
height: 0
|
62
|
+
};
|
63
|
+
}, [video]);
|
64
|
+
const rotation = useMemo(() => {
|
65
|
+
var _video$rotation;
|
66
|
+
return (_video$rotation = video === null || video === void 0 ? void 0 : video.rotation()) !== null && _video$rotation !== void 0 ? _video$rotation : 0;
|
38
67
|
}, [video]);
|
68
|
+
const frameDuration = 1000 / framerate;
|
69
|
+
const currentFrameDuration = Math.floor(frameDuration);
|
70
|
+
Rea.useAnimatedReaction(() => isPaused.value, paused => {
|
71
|
+
if (paused) {
|
72
|
+
video === null || video === void 0 || video.pause();
|
73
|
+
} else {
|
74
|
+
lastTimestamp.value = -1;
|
75
|
+
video === null || video === void 0 || video.play();
|
76
|
+
}
|
77
|
+
});
|
78
|
+
Rea.useAnimatedReaction(() => seek.value, value => {
|
79
|
+
if (value !== null) {
|
80
|
+
video === null || video === void 0 || video.seek(value);
|
81
|
+
currentTime.value = value;
|
82
|
+
seek.value = null;
|
83
|
+
}
|
84
|
+
});
|
85
|
+
Rea.useAnimatedReaction(() => volume.value, value => {
|
86
|
+
video === null || video === void 0 || video.setVolume(value);
|
87
|
+
});
|
39
88
|
Rea.useFrameCallback(frameInfo => {
|
89
|
+
"worklet";
|
90
|
+
|
40
91
|
if (!video) {
|
41
92
|
return;
|
42
93
|
}
|
43
|
-
if (
|
44
|
-
video.seek(seek.value);
|
45
|
-
seek.value = null;
|
46
|
-
lastTimestamp.value = -1;
|
47
|
-
startTimestamp.value = -1;
|
48
|
-
}
|
49
|
-
if (isPaused.value && lastTimestamp.value !== -1) {
|
94
|
+
if (isPaused.value) {
|
50
95
|
return;
|
51
96
|
}
|
52
|
-
const
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
// Initialize start timestamp
|
57
|
-
if (startTimestamp.value === -1) {
|
58
|
-
startTimestamp.value = timestamp;
|
97
|
+
const currentTimestamp = frameInfo.timestamp;
|
98
|
+
if (lastTimestamp.value === -1) {
|
99
|
+
lastTimestamp.value = currentTimestamp;
|
59
100
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if (currentTimestamp > duration && looping.value) {
|
67
|
-
video.seek(0);
|
68
|
-
startTimestamp.value = timestamp;
|
101
|
+
const delta = currentTimestamp - lastTimestamp.value;
|
102
|
+
const isOver = currentTime.value + delta > duration;
|
103
|
+
if (isOver && looping.value) {
|
104
|
+
seek.value = 0;
|
105
|
+
currentTime.value = seek.value;
|
106
|
+
lastTimestamp.value = currentTimestamp;
|
69
107
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
if (lastTimestamp.value === -1 || delta >= currentFrameDuration) {
|
75
|
-
const img = video.nextImage();
|
76
|
-
if (img) {
|
77
|
-
if (currentFrame.value) {
|
78
|
-
currentFrame.value.dispose();
|
79
|
-
}
|
80
|
-
if (Platform.OS === "android") {
|
81
|
-
currentFrame.value = img.makeNonTextureImage();
|
82
|
-
} else {
|
83
|
-
currentFrame.value = img;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
lastTimestamp.value = timestamp;
|
108
|
+
if (delta >= currentFrameDuration && !isOver) {
|
109
|
+
setFrame(video, currentFrame);
|
110
|
+
currentTime.value += delta;
|
111
|
+
lastTimestamp.value = currentTimestamp;
|
87
112
|
}
|
88
113
|
});
|
89
114
|
useEffect(() => {
|
90
115
|
return () => {
|
91
116
|
// TODO: should video simply be a shared value instead?
|
92
|
-
runOnUI(disposeVideo)();
|
117
|
+
Rea.runOnUI(disposeVideo)(video);
|
93
118
|
};
|
94
|
-
}, [
|
95
|
-
return
|
119
|
+
}, [video]);
|
120
|
+
return {
|
121
|
+
currentFrame,
|
122
|
+
currentTime,
|
123
|
+
duration,
|
124
|
+
framerate,
|
125
|
+
rotation,
|
126
|
+
size
|
127
|
+
};
|
96
128
|
};
|
97
129
|
//# sourceMappingURL=useVideo.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["useEffect","useMemo","Skia","Platform","Rea","setFrame","video","currentFrame","img","nextImage","value","dispose","OS","makeNonTextureImage","defaultOptions","looping","paused","seek","currentTime","volume","useOption","defaultValue","useSharedValue","isSharedValue","disposeVideo","useVideo","source","userOptions","_userOptions$paused","_userOptions$looping","_userOptions$seek","_userOptions$volume","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","runOnUI"],"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,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAE1C,SAASC,IAAI,QAAQ,iBAAiB;AAEtC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,OAAOC,GAAG,MAAM,mBAAmB;AAWnC,MAAMC,QAAQ,GAAGA,CAACC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A,KAAK,CAAC,CAAC;EAEX,OAAO;IACLC,YAAY;IACZW,WAAW;IACXiB,QAAQ;IACRE,SAAS;IACTM,QAAQ;IACRJ;EACF,CAAC;AACH,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
|
-
|
6
|
-
|
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
|
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,QAAQ,OAAO;AAGtC,SAASC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AAExD,SAASC,KAAK,QAAQ,UAAU;AAShC,OAAO,MAAMC,MAAM,GAAGA,CACpBC,GAAQ,EACRC,GAAW,EACXC,GAAW,EACXC,QAA4B,GAAG,CAAC,KAC7B;EACH,SAAS;;EACT,MAAMC,KAAK,GAAGR,QAAQ,CACpBI,GAAG,EACHG,QAAQ,KAAK,EAAE,IAAIA,QAAQ,KAAK,GAAG,GAC/B;IAAEE,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE,CAAC;IAAEC,KAAK,EAAEN,GAAG,CAACO,MAAM;IAAEA,MAAM,EAAEP,GAAG,CAACM;EAAM,CAAC,GACpDN,GAAG,EACPC,GACF,CAAC;EACD,MAAMO,MAAM,GAAGZ,SAAS,CAACO,KAAK,CAACH,GAAG,EAAEG,KAAK,CAACF,GAAG,CAAC;EAC9C,IAAIC,QAAQ,KAAK,EAAE,EAAE;IACnB,OAAO,CACL,GAAGM,MAAM,EACT;MAAEC,SAAS,EAAE,CAACT,GAAG,CAACO,MAAM,EAAE,CAAC;IAAE,CAAC,EAC9B;MAAEG,MAAM,EAAEC,IAAI,CAACC,EAAE,GAAG;IAAE,CAAC,CACxB;EACH;EACA,IAAIV,QAAQ,KAAK,GAAG,EAAE;IACpB,OAAO,CACL,GAAGM,MAAM,EACT;MAAEC,SAAS,EAAE,CAACT,GAAG,CAACM,KAAK,EAAEN,GAAG,CAACO,MAAM;IAAE,CAAC,EACtC;MAAEG,MAAM,EAAEC,IAAI,CAACC;IAAG,CAAC,CACpB;EACH;EACA,IAAIV,QAAQ,KAAK,GAAG,EAAE;IACpB,OAAO,CACL,GAAGM,MAAM,EACT;MAAEC,SAAS,EAAE,CAAC,CAAC,EAAET,GAAG,CAACM,KAAK;IAAE,CAAC,EAC7B;MAAEI,MAAM,EAAE,CAACC,IAAI,CAACC,EAAE,GAAG;IAAE,CAAC,CACzB;EACH;EACA,OAAOJ,MAAM;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 =>
|
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)
|
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,8 +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;
|
9
|
+
rotation(): VideoRotation;
|
10
|
+
size(): {
|
11
|
+
width: number;
|
12
|
+
height: number;
|
13
|
+
};
|
14
|
+
pause(): void;
|
15
|
+
play(): void;
|
16
|
+
setVolume(volume: number): void;
|
8
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}\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":""}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Picture\";\nexport * from \"./Data\";\nexport * from \"./SVG\";\nexport * from \"./Surface\";\nexport * from \"./Vertices\";\nexport * from \"./RuntimeEffect\";\nexport * from \"./Shader\";\nexport * from \"./Image\";\nexport * from \"./AnimatedImage\";\nexport * from \"./ColorFilter\";\nexport * from \"./ImageFilter\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Paint\";\nexport * from \"./Path\";\nexport * from \"./Color\";\nexport * from \"./Canvas\";\nexport * from \"./ContourMeasure\";\nexport * from \"./MaskFilter\";\nexport * from \"./Matrix\";\nexport * from \"./PathEffect\";\nexport * from \"./Point\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./RSXform\";\nexport * from \"./JsiInstance\";\nexport * from \"./Skia\";\nexport * from \"./TextBlob\";\nexport * from \"./Size\";\nexport * from \"./Paragraph\";\nexport * from \"./Matrix4\";\nexport * from \"./NativeBuffer\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,iBAAiB;AAC/B,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,gBAAgB"}
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Picture\";\nexport * from \"./Data\";\nexport * from \"./SVG\";\nexport * from \"./Surface\";\nexport * from \"./Vertices\";\nexport * from \"./RuntimeEffect\";\nexport * from \"./Shader\";\nexport * from \"./Image\";\nexport * from \"./AnimatedImage\";\nexport * from \"./ColorFilter\";\nexport * from \"./ImageFilter\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Paint\";\nexport * from \"./Path\";\nexport * from \"./Color\";\nexport * from \"./Canvas\";\nexport * from \"./ContourMeasure\";\nexport * from \"./MaskFilter\";\nexport * from \"./Matrix\";\nexport * from \"./PathEffect\";\nexport * from \"./Point\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./RSXform\";\nexport * from \"./JsiInstance\";\nexport * from \"./Skia\";\nexport * from \"./TextBlob\";\nexport * from \"./Size\";\nexport * from \"./Paragraph\";\nexport * from \"./Matrix4\";\nexport * from \"./NativeBuffer\";\nexport * from \"./Video\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,iBAAiB;AAC/B,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,kBAAkB;AAChC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,QAAQ;AACtB,cAAc,YAAY;AAC1B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,cAAc,WAAW;AACzB,cAAc,gBAAgB;AAC9B,cAAc,SAAS"}
|
@@ -1,12 +1,21 @@
|
|
1
|
-
import {
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
2
|
import type { SkImage } from "../../skia/types";
|
3
3
|
type Animated<T> = SharedValue<T> | T;
|
4
|
-
|
5
|
-
playbackSpeed: Animated<number>;
|
4
|
+
interface PlaybackOptions {
|
6
5
|
looping: Animated<boolean>;
|
7
6
|
paused: Animated<boolean>;
|
8
7
|
seek: Animated<number | null>;
|
9
|
-
|
8
|
+
volume: Animated<number>;
|
10
9
|
}
|
11
|
-
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) =>
|
10
|
+
export declare const useVideo: (source: string | null, userOptions?: Partial<PlaybackOptions>) => {
|
11
|
+
currentFrame: SharedValue<SkImage | null>;
|
12
|
+
currentTime: SharedValue<number>;
|
13
|
+
duration: number;
|
14
|
+
framerate: number;
|
15
|
+
rotation: import("../../skia/types").VideoRotation;
|
16
|
+
size: {
|
17
|
+
width: number;
|
18
|
+
height: number;
|
19
|
+
};
|
20
|
+
};
|
12
21
|
export {};
|